﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SlimDX;
using Gype.UI;

namespace Gype.GUI.Components
{
    public class MenuBarPopupItem
    {
        public MenuBarPopupItem(object item)
        {
            if (item == null)
                throw new ArgumentNullException();

            mObject = item;
        }

        internal void RenderObject(Vector2 position, Vector2 size)
        {
            if (mTarget == null)
                return;

            if (IsHovered)
            {
                mTarget.FillRectangle(new Vector2(position.X - 1, position.Y), new Vector2(size.X + 2, size.Y), BrushCollection.MenuBarPopupItemHover);
            }
            mTextRender.DrawText(Text, position + new Vector2(3, 1.5f), new Vector2(size.X - 6, 16));
        }

        internal void AttachedToPopup(MenuBarPopup popup)
        {
            mTextRender = new TextElement(TextCollection.Arial);
            mTextRender.Alignment = TextAlignement.Left;
            mTarget = mTextRender.Target;
        }

        internal string Text { get { return mObject.ToString(); } }

        internal bool IsHovered = false;

        private object mObject;
        private Rendertarget mTarget;
        private TextElement mTextRender;
    }
}
